//
//  SuggestionVC.m
//  Ufan
//
//  Created by yangqingluo on 16/1/14.
//  Copyright © 2016年 yangqingluo. All rights reserved.
//

#import "SuggestionVC.h"
#import "XHMessageTextView.h"

@interface SuggestionVC()<UITextViewDelegate,UITextFieldDelegate>

@property (strong, nonatomic) XHMessageTextView *suggestionTextView;
@property (strong, nonatomic) UITextField *contactTextField;

@end

@implementation SuggestionVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = RGBA(245, 245, 245, 1.0);
    [self setupBarButtonItem];
    
    UIView *upView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, 220)];
    upView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:upView];
    
    UIView *line1View = [[UIView alloc]initWithFrame:CGRectMake(0, upView.height - 1, upView.width, 1)];
    line1View.backgroundColor = UFCOLOR_GRAYLINE;
    [upView addSubview:line1View];
    
    UIView *line2View = [[UIView alloc]initWithFrame:CGRectMake(0, upView.height - 61, upView.width, 1)];
    line2View.backgroundColor = UFCOLOR_GRAYLINE;
    [upView addSubview:line2View];
    
    self.suggestionTextView.frame = CGRectMake(15, 15, upView.width - 30, line2View.top - 30);
    [upView addSubview:self.suggestionTextView];
    [self.suggestionTextView becomeFirstResponder];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(15, line2View.bottom, upView.width - 30, line1View.top - line2View.bottom)];
    label.font = [UIFont systemFontOfSize:16.0];
    label.text = @"联系方式";
    [upView addSubview:label];
    
    self.contactTextField.frame = CGRectMake(105, line2View.bottom, upView.width - 130, line1View.top - line2View.bottom);
    [upView addSubview:self.contactTextField];
}


- (void)setupBarButtonItem{
    self.title = @"反馈意见";
    
    UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 64, 44)];
    [backButton setImage:[UIImage imageNamed:@"nav_back.png"] forState:UIControlStateNormal];
    [backButton setImageEdgeInsets:UIEdgeInsetsMake(12, 0, 12, 48)];
    backButton.tag = 988;
    [backButton addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    [self.navigationItem setLeftBarButtonItem:backItem];
    
    UIButton *saveButton = [[UIButton alloc] initWithFrame:CGRectMake(self.navigationController.navigationBar.width - 64, 0, 64, 44)];
    [saveButton setTitle:@"发送" forState:UIControlStateNormal];
    saveButton.titleLabel.font = [UIFont systemFontOfSize:16.0];
    saveButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    saveButton.tag = 989;
    [saveButton addTarget:self action:@selector(send) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *saveItem = [[UIBarButtonItem alloc] initWithCustomView:saveButton];
    [self.navigationItem setRightBarButtonItem:saveItem];
}

-(void)goBack{
    [self hideHud];
    [self dismissKeyBoard];
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)send{
    [self dismissKeyBoard];
    
    if (self.suggestionTextView.text.length) {
        [self showHudInView:self.view hint:nil];
        [self performSelector:@selector(goBack) withObject:nil afterDelay:1.0];
        //            [self.navigationController showHint:@"反馈意见已发送"];
    }
    else{
        [self showHint:@"还没填写内容哦~"];
    }
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self dismissKeyBoard];
}

-(void)dismissKeyBoard{
    [self.view endEditing:YES];
}

#pragma getter

- (XHMessageTextView *)suggestionTextView{
    if (!_suggestionTextView) {
        _suggestionTextView = [[XHMessageTextView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, 40)];
        _suggestionTextView.placeHolder = @"请在这里写下对锦食的感受，我们将不断进步，为您做得更好~";
        _suggestionTextView.font = [UIFont systemFontOfSize:16.0];
        _suggestionTextView.backgroundColor = [UIColor clearColor];
        _suggestionTextView.showsVerticalScrollIndicator = YES;
        _suggestionTextView.showsHorizontalScrollIndicator = NO;
        _suggestionTextView.delegate = self;
    }
    
    return _suggestionTextView;
}

- (UITextField *)contactTextField{
    if (!_contactTextField){
        _contactTextField = [UITextField new];
        _contactTextField.borderStyle = UITextBorderStyleNone;
        _contactTextField.delegate = self;
        _contactTextField.placeholder = @"邮箱、qq、手机皆可";
        _contactTextField.font = [UIFont systemFontOfSize:16.0];
        _contactTextField.clearButtonMode = UITextFieldViewModeAlways;
    }
    
    return _contactTextField;
}

@end
